/*******************************************************************
 *
 * Copyright (C), 2021-2022, LS, All rights reserved.
 *
 * Author      : 
 * Create Time : 2021-09-17
 * Version     : v0.1
 * Description : 
 *******************************************************************/
 
#ifndef _LS_BLE_CUSTOM_API_H_
#define _LS_BLE_CUSTOM_API_H_

/*----------------------------Head file----------------------------*/
#include "stdint.h"
#include "stdbool.h"

/*----------------------------macro file---------------------------*/
#define CUSTOM_PROTO_SUCCESS    0

#define DEV_MAC_INVALID         0
#define DEV_MAC_VALID           1

/*----------------------------type define--------------------------*/
typedef enum {
    LS_BLE_CUS_CB_EVT_NULL = 0,
    
    LS_BLE_CUS_CB_EVT_CONNECTED,
    LS_BLE_CUS_CB_EVT_DISCONNECT,
    
    LS_BLE_CUS_CB_EVT_IND_ENABLE,
    LS_BLE_CUS_CB_EVT_IND_DISABLE,
    LS_BLE_CUS_CB_EVT_IND_COMPLETE,
    
    LS_BLE_CUS_CB_EVT_RECEIVE_DATA,
    
} ls_ble_cus_cb_evt_t;

typedef struct {
    ls_ble_cus_cb_evt_t evt;
    uint8_t cmd;
    uint8_t *p_data;
    uint16_t len;
} ls_ble_cus_cb_evt_param_t;


typedef enum {
	SKIP_CMD_NULL         = 0,
	SKIP_CMD_DISP_DATA    = 0x01,
	SKIP_CMD_REALTIME_RET = 0x02,
	SKIP_CMD_HISTORY_RET  = 0x03,
	
	SKIP_CMD_SYNC_TIME    = 0x80,
	SKIP_CMD_START_SKIP   = 0x81,
	SKIP_CMD_STOP_SKIP    = 0x82,
	SKIP_CMD_SEARCH_DEV   = 0x83,
	
	SKIP_CMD_DEV_RESET    = 0xF7,
	SKIP_CMD_DEV_REVERT   = 0xF8,
	SKIP_CMD_SET_ADV_NAME = 0xF9,
	SKIP_CMD_GO_BURN_MODE = 0xFA,
	SKIP_CMD_BURN_MAC     = 0xFB,
	SKIP_CMD_CHECK_BURN   = 0xFC,
	SKIP_CMD_FAC_TEST     = 0xFD,
	SKIP_CMD_BURN_DEV_SEQ = 0xFE,
	SKIP_CMD_UNKNOW       = 0xFF
} custom_cmd_t;


#pragma pack(1)
typedef struct {
	uint8_t mode;
	uint16_t setting;
	uint16_t total_secs;
	uint16_t total_cnts;
	uint8_t trip_num;
	uint8_t batt_per;
	uint16_t skip_valid_sec;
} custom_skip_disp_data_t;


typedef struct {
	uint32_t utc;
	uint16_t timezone_mins;
} custom_sync_time_t;


typedef struct {
	uint8_t mode;
	uint16_t setting;
	uint32_t utc;
	uint16_t cnt_down_start;
} custom_start_skip_t;
#pragma pack()

/*----------------------------var define---------------------------*/

/*-------------------------func declaration------------------------*/
extern void ls_ble_custom_callback(ls_ble_cus_cb_evt_param_t* param);
extern void ls_ble_custom_rx_payload_handle(uint8_t cmd, uint8_t *payload, uint16_t payload_len);
extern void ls_ble_custom_send_msg(uint8_t cmd);

extern void ls_ble_custom_mem_delay_send_timer_start(void);
extern void ls_ble_custom_mem_resend_timer_stop(void);
extern void ls_ble_custom_mem_resend_timer_start(void);
extern void ls_ble_custom_mem_resend_timeout_handle(void);
extern bool ls_ble_custom_upload_unsent_skip_ret(bool increase);

/*-----------------------------------------------------------------*/

#endif
